<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>产品档案恢复页面</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap-table.min.css">
    <script src="../js/jquery-2.1.1.min.js"></script>
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script src="../js/bootstrap-table.min.js"></script>
    <script src="../js/bootstrap-table-zh-CN.min.js" ></script>
    <script>




        $(function() {

            //页面初始化给变更人赋值
            $.ajax({
                type: 'POST',
                url: '/userShow.action',
                success: function (user) {
                    $('#changer').val(user.loginId);
                }
            })

            //I,II,III级编号联动
            var iNum1;
            var iNum2;
            var aProvince = ["电子", "机械", "商品"];
            var aCity = [["计算机", "手机", "平板", "手表"],
                ["焊接器", "液压器"],
                ["学习用品", "生活用品"]];
            var aCountry = [[
                ["cpu", "gpu", "内存条", "固态硬盘", "网卡"],
                ["处理器", "显示器"],
                ["触摸屏", "接口"],
                ["表芯", "表带"],
            ],
                [
                    ["燃烧带", "焊锡", "焊接头"],
                    ["起重器", "铁块"]
                ],
                [
                    ["钢笔"],
                    ["枕头", "被子", "毛巾", "牙膏"]
                ]];


            for (var i = 0; i < aProvince.length; i++) {
                $('#SfirstKindName').append('<option>' + aProvince[i] + '</option>');
            }
            ;
            $('#SfirstKindName').change(function () {
                $('#SsecondKindName').children().not(':eq(0)').remove();
                $('#SthirdKindName').children().not(':eq(0)').remove();
                iNum1 = $(this).children('option:selected').index();
                var aaCity = aCity[iNum1 - 1];
                for (var j = 0; j < aaCity.length; j++) {
                    $('#SsecondKindName').append('<option>' + aaCity[j] + '</option>');
                }
            });
            $('#SsecondKindName').change(function () {
                $('#SthirdKindName').children().not(':eq(0)').remove();
                iNum2 = $(this).children('option:selected').index();
                var aaCountry = aCountry[iNum1 - 1][iNum2 - 1];
                for (var k = 0; k < aaCountry.length; k++) {
                    $('#SthirdKindName').append('<option>' + aaCountry[k] + '</option>');
                }
            })

            for (var i = 0; i < aProvince.length; i++) {
                $('#firstKindName').append('<option>' + aProvince[i] + '</option>');
            }
            ;
            $('#firstKindName').change(function () {
                $('#secondKindName').children().not(':eq(0)').remove();
                $('#thirdKindName').children().not(':eq(0)').remove();
                iNum1 = $(this).children('option:selected').index();
                var aaCity = aCity[iNum1 - 1];
                for (var j = 0; j < aaCity.length; j++) {
                    $('#secondKindName').append('<option>' + aaCity[j] + '</option>');
                }
            });
            $('#secondKindName').change(function () {
                $('#thirdKindName').children().not(':eq(0)').remove();
                iNum2 = $(this).children('option:selected').index();
                var aaCountry = aCountry[iNum1 - 1][iNum2 - 1];
                for (var k = 0; k < aaCountry.length; k++) {
                    $('#thirdKindName').append('<option>' + aaCountry[k] + '</option>');
                }
            })


            //页面加载完初始化表格数据
            $('#table').bootstrapTable({
                //请求方式  get请求中文会乱码，建议使用post请求
                method: 'get',
                //请求头部的设置
                contentType: 'application/json;charset=utf-8',
                //路径
                url: '/QueryDeletedProduct.action',
                //设置交替行样式
                striped: true,
                //初始显示页号
                pageNumber: 1,
                //设置表格高度
                height: 500,

                //是否显示分页
                pagination: true,
                //设置是服务端分页还是客户端分页
                sidePagination: 'server',
                //页大小
                pageSize: 5,
                //分页列表
                pageList: [3, 5, 6, 10],
                //上传到服务端的参数
                queryParams: function (params) {
                    return {
                        // 计算页号(当前页)
                        pageNum: (params.offset / params.limit) + 1,
                        // 计算页大小
                        pageSize: params.limit,

                        productId: $('#SproductId').val(),
                        productName: $('#SproductName').val(),
                        firstKindName: $('#SfirstKindName').val(),
                        secondKindName: $('#SsecondKindName').val(),
                        thirdKindName: $('#SthirdKindName').val(),
                    };
                },
                // 定义列名
                columns: [
                    {title: '产品编号', field: 'productId', align: 'center'},
                    {title: '产品名称', field: 'productName', align: 'center'},
                    {title: '制造商', field: 'factoryName', align: 'center'},
                    {title: 'I级分类', field: 'firstKindName', align: 'center'},
                    {title: 'II级分类', field: 'secondKindName', align: 'center'},
                    {title: 'III级分类', field: 'thirdKindName', align: 'center'},
                    {
                        title: '用途类型', field: 'type', align: 'center',
                        formatter: function (value) {
                            if (value == 'Y001-1') {
                                return '商品';
                            }
                            if (value == 'Y001-2') {
                                return '物料';
                            }
                        }
                    },
                    {
                        title: '档次级别', field: 'productClass', align: 'center',
                        formatter: function (value) {
                            if (value == 'D001-1') {
                                return '高档';
                            }
                            if (value == 'D001-2') {
                                return '中档';
                            }
                            if (value == 'D001-3') {
                                return '低档';
                            }
                        }
                    },
                    {title: '计量单位', field: 'personalUnit', align: 'center'},
                    {title: '计量值', field: 'personalValue', align: 'center'},
                    {title: '保修期', field: 'warranty', align: 'center'},
                    {
                        title: '操作', field: 'id', align: 'center',
                        formatter: function (value, row, index) {
                            var btn = "<button type='button' class='btn btn-primary' data-toggle='modal' data-target='#myModal' onclick='queryProductProfile(" + JSON.stringify(row) + ")'>恢复</button>";
                            return btn;
                        }
                    },
                ]

            });

            //点击查询按钮后刷新表,并清空搜索条件
            $('#searchProduct').click(function () {
                $("#table").bootstrapTable("refresh");
                $('#SproductId').val('');
                $('#SproductName').val('');
                $('#SfirstKindName').val('');
                $('#SsecondKindName').val('');
                $('#SthirdKindName').val('');
            });

            //点击变更按钮后将当前产品信息展示到模态框上
            queryProductProfile = function (a) {
                $('#name').text(a.productName);
                $('#id').val(a.id);
                $('#fileChangeAmount').val(a.fileChangeAmount);
            }


            //点击确定按钮后异步删除产品档案信息
            $('#deleteProductBtn').click(function () {

                //页面初始化给创建时间赋值
                var date = new Date();
                $('#changeTime').val(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds());
                $('#myModal').modal('hide');
                var ProductObj = {
                    id: $('#id').val(),
                    changer: $('#changer').val(),
                    changeTime: $('#changeTime').val(),
                    fileChangeAmount:$('#fileChangeAmount').val()
                };
                var jsonProduct = JSON.stringify(ProductObj);

                //执行异步添加产品档案登记方法
                $.ajax({
                    type: 'post',
                    url: '/RecoveryProduct.action',
                    contentType: 'application/json;charset=utf-8',
                    data: jsonProduct,
                    success: function () {
                        alert('恢复成功');
                        $("#table").bootstrapTable("refresh");
                    },
                });


            });



        });



    </script>
</head>
<body>


<!--展示当前变更产品的信息 -->
<div class="form-inline breadcrumb" style="width: 90%;background-color: white;">
    <label class="mb-2 mr-sm-2">产品编号</label><input type="text" class="form-control" style="width: 180px" id="SproductId">
    <label class="mb-2 mr-sm-2">产品名称</label><input type="text" class="form-control" id="SproductName" style="width: 180px">
    <label class="mb-2 mr-sm-2">I级分类</label>
    <select class="form-control mb-2 mr-sm-2" id="SfirstKindName">
        <option value="">--请选择--</option>
    </select>

    <label class="mb-2 mr-sm-2">II级分类</label>
    <select class="form-control mb-2 mr-sm-2" id="SsecondKindName">
        <option value="">--请选择--</option>
    </select>

    <label class="mb-2 mr-sm-2">III级分类</label>
    <select class="form-control mb-2 mr-sm-2" id="SthirdKindName">
        <option value="">--请选择--</option>
    </select>

    <button class='btn btn-success' id="searchProduct">搜索</button>
</div>

<!-- 产品恢复提示模态框 -->
<div class="modal fade" id="myModal">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">

            <!-- 模态框主体 -->
            <div class="modal-body">
                <h4>是否确定恢复<h4 id="name" style="color: #51bf2e"></h4>？</h4>
            </div>

            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" id="deleteProductBtn" class="btn btn-success" data-toggle="modal" data-target="#myModal" >确定</button>
                <button type="button" class="btn btn-dark" data-toggle="modal" data-target="#myModal" >取消</button>
            </div>

        </div>
    </div>
</div>

<table id="table"></table>

<!--id主键自增 -->
<input type="text" id="id" style="display: none">
<!--变更次数 -->
<input type="text" id="fileChangeAmount" style="display: none">
<!--变更人 -->
<input type="text" id="changer" style="display: none">
<!--变更时间 -->
<input type="text" id="changeTime" style="display: none">

</body>

</html>